
<!--generated with sswg-->
<style>
    html {max-width: 100%; margin: auto; color: #333333;}
    a.button {padding: 15px 32px; background-color: #555; border-radius: 2em; border-width: 0px; text-decoration: none; color: white; font-size: 25.0px; line-height: 2.5em;}
    a.button:hover {background-color: #777}
    a.button_big {padding: 0.5em; background-image: linear-gradient(to top, #427b0e, #9ba97d); background-color: lightgray; background-blend-mode: multiply; border-radius: .75em; border-width: 0px; text-decoration: none; min-width: 150px; max-width: 150px; min-height: 150px; max-height: 150px; display: inline-block; vertical-align: top; margin: 4px 4px 10px 4px; color: white; font-size: 25.0px; background-size: auto 100%; background-position-x: center;}
    a.button_big:hover {background-color: white; color: #e6d23f; text-decoration: underline;}
    mark {background: #ccff99;}
    span {background-color: rgba(0, 0, 0, 0.55); padding: .1em; line-height: 1.35em;}
    img {max-width: 100%; vertical-align: top;}
    .code_block {background-color: whitesmoke; padding: 10px; margin: 0; font-family: monospace; font-size: 20; font-weight: normal; white-space: pre;}

    purple {color: hsl(289.0, 50%, 50%);}
    gray {color: gray;}
    olive {color: olive;}
    yellow {color: darkgoldenrod;}
    green {color: seagreen;}
    blue {color: hsl(210, 50%, 50%);}

</style>
<html>
<left>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>introduction_tutorial</title>
<br>

<a href=" documentation.html" class="button">← Back</a><br>
<div style="font-family: arial;font-size: 20.0px;max-width: 1024px; margin: auto;">
<div style="font-weight: bold;font-size: 60.0px;">
Introduction Tutorial<br>
<div style="font-weight: normal;font-size: 20.0px;">
<br>
<div style="font-size: 40.0px;font-weight: bold;">
<div id="Creating and running a game"/><br>
Creating and running a game<br>
<div style="font-size: 20.0px;font-weight: normal;">
<br>
1) Open your preferred text editor. If you're new to programming, here are some suggestions:<br>
&nbsp;&nbsp;&nbsp;&nbsp;* Atom<br>
&nbsp;&nbsp;&nbsp;&nbsp;* Visual Studio Code<br>
&nbsp;&nbsp;&nbsp;&nbsp;* Sublime Text<br>
<br>
<br>
2)<br>
&nbsp;&nbsp;&nbsp;&nbsp;Create a new folder for your project. This will contain scripts and assets.<br>
&nbsp;&nbsp;&nbsp;&nbsp;For ursina to find 3d models and textures, they should be in the same folder or in<br>
&nbsp;&nbsp;&nbsp;&nbsp;a folder below the starting script.<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;In this folder, create a new file called main.py. This will contain out little game.<br>
<br>
<br>
3) At the top of the file, write:<br>
<div class="code_block" style="margin-left: 2em;"><purple>from</purple> ursina <purple>import</purple> *
</div><br>
&nbsp;&nbsp;&nbsp;&nbsp;This will import all the necessary things we need from the engine in one line.<br>
&nbsp;&nbsp;&nbsp;&nbsp;It means something like 'from ursina import all'. It's also possible to import parts of the engine<br>
&nbsp;&nbsp;&nbsp;&nbsp;like this:<br>
<div class="code_block" style="margin-left: 2em;"><purple>from</purple> ursina.prefabs <purple>import</purple> Button
</div><br>
&nbsp;&nbsp;&nbsp;&nbsp;Or import something that's not included by default:<br>
<div class="code_block" style="margin-left: 2em;"><purple>from</purple> ursina.prefabs.first_person_controller <purple>import</purple> FirstPersonController
</div><br>
<br>
4) Here's a really basic example game with comments to explain what were doing.<br>
&nbsp;&nbsp; We will simply make a orange box move right and left when we press 'd' or 'a'.<br>
<br>
<div class="code_block" style="margin-left: 1em;"><purple>from</purple> ursina <purple>import</purple> *

<gray># create a window</gray>
app = Ursina()

<gray># most things in ursina are Entities. An <olive>Entity</olive> is a thing you place in the world.</gray>
<gray># you can think of them as GameObjects in Unity or Actors in Unreal.</gray>
<gray># the first paramenter tells us the <olive>Entity</olive><green>'s model will be a <yellow>3</yellow>d-model called '</green>cube'.</gray>
<gray># ursina includes some basic models like <green>'cube'</green>, <green>'sphere'</green> and <green>'quad'</green>.</gray>

<gray># the next parameter tells us the model's color should be orange.</gray>

<gray># <green>'scale_<olive>y</olive>=<yellow>2</yellow>'</green> tells us how big the entity should be in the vertical axis, how tall it should be.</gray>
<gray># in ursina, positive x is right, positive y is up, and positive z is forward.</gray>

player = <olive>Entity</olive>(<olive>model</olive>=<green>'cube'</green>, <olive>color</olive>=color.orange, scale_<olive>y</olive>=<yellow>2</yellow>)

<gray># create a function called <green>'update'</green>.</gray>
<gray># this will automatically get called by the engine every frame.</gray>

<purple>def</purple> update():
    player.x += held_keys[<green>'d'</green>] * time.dt
    player.x -= held_keys[<green>'a'</green>] * time.dt

<gray># this part will make the player move left or right based on our input.</gray>
<gray># to check which keys are held down, we can check the held_keys dictionary.</gray>
<gray># <yellow>0</yellow> means <purple>not</purple> pressed and <yellow>1</yellow> means pressed.</gray>
<gray># time.dt is simply the time since the last frame. by multiplying with this, the</gray>
<gray># player will move at the same speed regardless of how fast the game runs.</gray>


<purple>def</purple> input(key):
    <purple>if</purple> key == <green>'space'</green>:
        player.y += <yellow>1</yellow>
        invoke(setattr, player, <green>'y'</green>, player.y-<yellow>1</yellow>, dela<olive>y</olive>=.<yellow>2</yellow><yellow>5</yellow>)


<gray># start running the game</gray>
app.run()


</div><br>
<br>
5) Now we have to tell Python to run the script. To do this, open the command line and<br>
&nbsp;&nbsp; go to the current folder. An easy way to do this is to type 'cmd' in the address bar.<br>
&nbsp;&nbsp; Run the command below.<br>
<br>
<div class="code_block" style="margin-left: 1em;">python main.py
</div><br>
&nbsp;&nbsp; An alternative is to install the 'atom-python-run' package in Atom so you can start<br>
&nbsp;&nbsp; the game by pressing F5.<br>
<br>

</html>